<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-notice-edit" th:object="${notice}">
            <input id="noticeId" name="noticeId" th:field="*{noticeId}"  type="hidden">
            <div class="form-group">	
                <label class="col-sm-3 control-label">公告标题：</label>
                <div class="col-sm-8">
                    <input id="noticeTitle" name="noticeTitle" th:field="*{noticeTitle}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
				<label class="col-sm-3 control-label">公告类型：</label>
				<div class="col-sm-8">
					<select name="noticeType" class="form-control m-b" th:with="type=${@dictService.selectDictData('sys_notice_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict['dictLabel']}" th:value="${dict['dictValue']}" th:field="*{noticeType}"></option>
	                </select>
				</div>
			</div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">公告内容：</label>
                <div class="col-sm-8">
                    <input id="noticeContent" name="noticeContent" th:field="*{noticeContent}" type="hidden">
                    <div id="editor" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">
				<label class="col-sm-3 control-label">公告状态：</label>
				<div class="col-sm-8" th:with="type=${@dictService.selectDictData('sys_notice_status')}">
					<div th:each="dict : ${type}" th:class="${dict['cssClass']}">
						<input type="radio" th:id="${dict['dictCode']}" name="status" th:value="${dict['dictValue']}" th:field="*{status}">
						<label th:for="${dict['dictCode']}" th:text="${dict['dictLabel']}"></label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">发送对象：</label>
				<input type="hidden" name="selectids" id="selectids" th:field="*{selectids}">
				<div class="col-sm-2">
					<select id="d1" class="form-control m-b">
	                </select>
	            </div>
				<div class="col-sm-2">
					<select id="d2" class="form-control m-b">
	                </select>
	            </div>
				<div class="col-sm-2">
					<select id="d3" class="form-control m-b">
	                </select>
	            </div>
				<div class="col-sm-2">
					<select id="d4" class="form-control m-b">
	                </select>
				</div>
			</div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
    <script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
    <script type="text/javascript" th:inline="javascript">
	    $(function() {
		    $('.summernote').summernote({
				height : '220px',
				lang : 'zh-CN'
		    });
			var content = $("#noticeContent").val();
		    $('#editor').code(content);
	    });
	    
		var prefix = ctx + "module/notice"
		$("#form-notice-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			submitHandler: function(form) {
				var sHTML = $('.summernote').code();
				$("#noticeContent").val(sHTML);
				var d1 = $("#d1").val()==null?'0':$("#d1").val();
				var d2 = $("#d2").val()==null?'0':$("#d2").val();
				var d3 = $("#d3").val()==null?'0':$("#d3").val();
				var d4 = $("#d4").val()==null?'0':$("#d4").val();
				$("#selectids").val(d1+"|"+d2+"|"+d3+"|"+d4);
				$.operate.save(prefix + "/save", $('#form-notice-edit').serialize());
			}
		});
		
		function CLASS_LIANDONG_YAO(array)
		  {
		   //数组，联动的数据源
		  	this.array=array; 
		  	this.indexName='';
		  	this.obj='';
		  	//设置子SELECT
			// 参数：当前onchange的SELECT ID，要设置的SELECT ID
		      this.subSelectChange=function(selectName1,selectName2)
		  	{
		  	//try
		  	//{
		    var obj1=document.all[selectName1];
		    var obj2=document.all[selectName2];
		    var objName=this.toString();
		    var me=this;
		    obj1.onchange=function()
		    {
		    	me.optionChange(this.options[this.selectedIndex].value,obj2.id)
		    }
		  	}
		  	//设置第一个SELECT
			// 参数：indexName指选中项,selectName指select的ID
		  	this.firstSelectChange=function(indexName,selectName)  
		  	{
		  	this.obj=document.all[selectName];
		  	this.indexName=indexName;
		  	this.optionChange(this.indexName,this.obj.id)
		  	}
		  // indexName指选中项,selectName指select的ID
		  	this.optionChange=function (indexName,selectName)
		  	{
		    var obj1=document.all[selectName];
		    var me=this;
		    obj1.length=0;
		    obj1.options[0]=new Option("全部",'0');
		    for(var i=0;i<this.array.length;i++)
		    {	
		    	if(this.array[i][1]==indexName)
		    	{
		    	//alert(this.array[i][1]+" "+indexName);
		      obj1.options[obj1.length]=new Option(this.array[i][2],this.array[i][0]);
		    	}
		    }
		  	}	
		  }
		  	
		  var array=[[${selectList}]];
		  var array2=new Array();
		  for(var i=0;i<array.length;i++){
			  array2[i]=new Array(array[i].id,array[i].pid,array[i].name);
		  }
		  //--------------------------------------------
		  //这是调用代码
		  //设置数据源
		  var liandong2=new CLASS_LIANDONG_YAO(array2);
		  //设置第一个选择框
		  liandong2.firstSelectChange("根目录","d1");
		  //设置子选择框
		  liandong2.subSelectChange("d1","d2");
		  liandong2.subSelectChange("d2","d3");
		  liandong2.subSelectChange("d3","d4");
		  
		  $("#d1").change(function(){
				$("#d3").children().remove();
				$("#d4").children().remove();
		  });
		  $("#d2").change(function(){
				$("#d4").children().remove();
		  });
	</script>
</body>
</html>
